package com.jingogo.controller;

import com.jingogo.common.Result;
import com.jingogo.service.CustomerService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;

@Slf4j
@RestController
@RequestMapping("/customerService")
@Tag(name = "客服系统", description = "客服相关接口")
public class CustomerServiceController {

    @Autowired
    private CustomerService customerService;

    @PostMapping("/sendMessage")
    @Operation(summary = "用户发送消息", description = "用户向客服发送消息")
    @PreAuthorize("hasRole('USER')")
    public Result<String> sendMessage(@RequestParam @NotNull(message = "用户ID不能为空") Long userId,
                                    @RequestParam @NotNull(message = "消息内容不能为空") String message) {
        customerService.sendMessage(userId, message);
        return Result.success("消息发送成功");
    }

}
